package cn.wolfcode.controller;

import cn.wolfcode.domain.Dept;
import cn.wolfcode.domain.Result;
import cn.wolfcode.service.DeptService;
import cn.wolfcode.service.impl.DeptServiceImpl;
import com.mysql.cj.log.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;
    @GetMapping

    public Result list() {
        List<Dept> list = deptService.list();
        log.info("查询所有部门信息");
        return Result.success(list);
    }
    @DeleteMapping("/{id}")
public Result delete(@PathVariable Long id) {
        log.info("删除id:{}的部门",id);
        deptService.delete(id);
        return Result.success();
    }
@PostMapping
public Result save(@RequestBody Dept dept) {
    log.info("新增部门:{}",dept);
    deptService.save(dept);
    return Result.success();
}
@GetMapping("/{id}")
    public Result get(@PathVariable Long id) {
        log.info("根据id:{}查询部门信息",id);
        Dept dept =deptService.getById(id);
        return Result.success(dept);
}
@PutMapping
public Result update(@RequestBody Dept dept) {
        log.info("修改部门编号为:{}的名字改为{}",dept.getId(),dept.getName());
        deptService.update(dept);
        return Result.success();
}
}

